package com.example.springbootdemo.Service;

import java.util.Date;
import java.util.List;

import com.example.springbootdemo.entity.Category;
import com.example.springbootdemo.mappers.CategoryMapper;
import com.example.springbootdemo.utils.PageResult;
import com.example.springbootdemo.utils.PageUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * categoryService业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-01
 */
@Service
public class CategoryServiceImpl implements ICategoryService 
{
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 查询category
     * 
     * @param cid category主键
     * @return category
     */
    @Override
    public Category selectCategoryByCid(Long cid)
    {
        return categoryMapper.selectCategoryByCid(cid);
    }

    /**
     * 查询category列表
     * 
     * @param category category
     * @return category
     */
    @Override
    public PageResult selectCategoryList(Category category, int pageSize, int pageNum)
    {
        PageHelper.startPage(pageSize,pageNum);
        List<Category> list = categoryMapper.selectCategoryList(category);
        System.out.println(list.size());
        PageInfo<Category> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    @Override
    public PageResult selectCategoryGoodsList(Category category, int pageSize, int pageNum) {
        PageHelper.startPage(pageSize,pageNum);
        List<Category> list = categoryMapper.selectCategoryGoodsList(category);
        System.out.println(list.size());
        PageInfo<Category> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;    }

    /**
     * 新增category
     * 
     * @param category category
     * @return 结果
     */
    @Override
    public int insertCategory(Category category)
    {
        category.setCreateTime(new Date());
        return categoryMapper.insertCategory(category);
    }

    /**
     * 修改category
     * 
     * @param category category
     * @return 结果
     */
    @Override
    public int updateCategory(Category category)
    {
        category.setUpdateTime(new Date());
        return categoryMapper.updateCategory(category);
    }

    /**
     * 批量删除category
     * 
     * @param cids 需要删除的category主键
     * @return 结果
     */
    @Override
    public int deleteCategoryByCids(Long[] cids)
    {
        return categoryMapper.deleteCategoryByCids(cids);
    }

    /**
     * 删除category信息
     * 
     * @param cid category主键
     * @return 结果
     */
    @Override
    public int deleteCategoryByCid(Long cid)
    {
        return categoryMapper.deleteCategoryByCid(cid);
    }
}
